package components.propertyCtrls
{
/*
	red		: от -1 до 1
	green	: от -1 до 1
	blue	: от -1 до 1
*/
	import UIFree.controls.uif_scrollbar;
	import UIFree.uif_component;
	
	import UIUtils.uif_util;
	
	import flash.geom.Rectangle;
	
	public class c_colorBalance extends c_propertyBase {
		public static const WEIGHT: Number = 100;
		private var _red: uif_scrollbar;
		private var _green: uif_scrollbar;
		private var _blue: uif_scrollbar;
		
		public function c_colorBalance(parent:uif_component, aData:Object, y:Number, a_height:Number) {
			super(parent, aData, y, a_height);
		}
		
		override protected function createComponents():void {
			super.createComponents();
			var rect: Rectangle = componentRect;
			var h: Number = rect.height / 3;
			
			function createBar(ind: int, a_color: uint): uif_scrollbar {
				var bar: uif_scrollbar = new uif_scrollbar(This, rect.x, rect.y + ind * h, rect.width, h, 'scrollbar');
				bar.handle.style = uif_util.union(bar.handle.style, {
					fill_color: a_color
				});
				bar.addEvent(uif_scrollbar.SCROLLING, doChange);
				return bar;
			}
			
			_red = createBar(0, 0xFF0000);
			_green = createBar(1, 0x00FF00);
			_blue = createBar(2, 0x0000FF);
		}
		
		override protected function setData(value:Object):void {
			super.setData(value);
			_red.value 		= _data.value.red * 50 + 50;
			_green.value 	= _data.value.green * 50 + 50;
			_blue.value 	= _data.value.blue * 50 + 50;
		}
		
		override protected function getValue(): Object {
			return {
				red: (_red.value - 50) / 50,
				green: (_green.value - 50) / 50,
				blue: (_blue.value - 50) / 50
			};
		}		
	}
}